<!--
 * @Author: ChaiHongJun
 * @Date: 2021-03-23 18:10:14
 * @LastEditors: ChaiHongJun
 * @LastEditTime: 2021-04-28 14:54:10
 * @version: 
 * @Description: 推荐歌单组件
-->
<template>
  <div class="recommend-songs">
    <h2 class="title">推荐歌单</h2>
    <div class="list">
      <div
        class="item"
        v-for="track in getPersonalized"
        :key="track.id"
        @click="getDetail(track)"
      >
        <div class="wrapper">
          <a>
            <div class="cover">
              <div class="image">
                <el-image :src="track.picUrl" lazy></el-image>
              </div>
              <div class="count">
                <i class="arrow"></i>
                <span>{{ formatPlayCount(track.playCount) }}</span>
              </div>
            </div>
          </a>
        </div>
        <div class="info">
          <h2 class="name ellipsis-two">
            {{ track.name }}
          </h2>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { formatPlayCount } from "@/utils/index.js";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      loadingRecommend: false,
      limit: 24,
    };
  },
  mounted() {
    this.loadingRecommend = true;
    this.$store.dispatch("getPersonalized", this.limit);
    this.loadingRecommend = false;
  },
  computed: {
    ...mapGetters(["getPersonalized"]),
    formatPlayCount() {
      return (playCount) => {
        return formatPlayCount(playCount);
      };
    },
  },
  methods: {
    // 获取歌单详情
    // id 歌单id
    getDetail(track) {
      //进入到歌单详情页
      this.$router.push({
        name: "Detail",
        query: { id: track.id },
      });
    },
  },
};
</script>
<style lang="stylus" scoped>
.recommend-songs {
  margin-top: 40px;

  .title {
    margin: 0 0 15px 0;
  }
}

.list {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -15px;

  .item {
    flex: 0 0 12.5%;
    max-width: 12.5%;
    padding: 0 15px 30px;
    cursor: pointer;

    &.two {
      flex: 0 0 50%;
      max-width: 50%;
    }

    .wrapper {
      position: relative;
      padding-right: 10px;

      &:before, &:after {
        content: '';
        width: 100%;
        height: 100%;
        background-color: #d9d9d9;
        position: absolute;
        top: 0;
        transition: all 0.4s;
      }

      &:before {
        right: 6px;
        transform: scale(0.85);
        transform-origin: 100% 50%;
        z-index: 2;
        border-radius: 2px;
      }

      &:after {
        right: 4px;
        transform: scale(0.73);
        transform-origin: 100% 50%;
        z-index: 1;
        border-radius: 2px;
        opacity: 0.5;
      }

      .cover {
        position: relative;
        z-index: 2;
        padding-top: 100%;
        border-radius: 2px;
        background-color: #d9d9d9;

        .image {
          position: absolute;
          top: 0;
          left: 0;
          overflow: hidden;
          width: 100%;
          height: 100%;
          border-radius: 4px;

          &:after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: 2px;
            -webkit-box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.05) inset, -1px -1px 0 rgba(0, 0, 0, 0.05) inset;
            box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.05), inset -1px -1px 0 rgba(0, 0, 0, 0.05);
          }

          img {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 100%;
          }
        }

        .count {
          position: absolute;
          right: 16px;
          top: 1px;
          height: 24px;
          padding-left: 9px;
          background: url('https://img.alicdn.com/tfs/TB1xEGRub9YBuNjy0FgXXcxcXXa-268-48.png') no-repeat 0; // img.alicdn.com/tfs/TB1xEGRub9YBuNjy0FgXXcxcXXa-268-48.png) no-repeat 0;
          background-size: cover;
          color: #fff;
          font-size: 12px;
          font-weight: 700;
          line-height: 24px;
          display: flex;
          align-items: center;
          justify-content: center;

          .arrow {
            display: block;
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 4px 0 4px 6px;
            border-color: transparent transparent transparent #ffffff;
            margin-right: 5px;
          }

          &:after {
            content: '';
            position: absolute;
            right: -14px;
            top: 0;
            width: 14px;
            height: 24px;
            background: url('https://img.alicdn.com/tfs/TB1xEGRub9YBuNjy0FgXXcxcXXa-268-48.png') no-repeat 100%; // img.alicdn.com/tfs/TB1xEGRub9YBuNjy0FgXXcxcXXa-268-48.png) no-repeat 100%;
            background-size: cover;
          }
        }
      }
    }

    .info {
      margin-top: 15px;

      .name {
        font-size: 14px;
      }
    }

    &:hover {
      .wrapper {
        &:before, &:after {
          background: rgba(250, 40, 0, 0.1);
        }

        &:before {
          right: 4px;
        }

        &:after {
          right: 0px;
        }
      }
    }
  }
}
</style>